﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Automobile.service.Model;
using Automobile.service.Common;
using System.Data;
using System.Data.SqlClient;

namespace Automobile.service.DAL
{
    public class StockDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 库存管理——显示
        /// </summary>
        /// <returns></returns>
        public DataTable ShowListDataTable()
        {
            return helper.ExecDataTable_Proc("ShowStock");
        }
        /// <summary>
        /// 库存管理——添加
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int AddStock(Stock s)
        {
            SqlParameter[] addstock ={
                                        new SqlParameter("@num",s.Stock_num),
                                        new SqlParameter("@warm",s.Stock_warn),
                                        new SqlParameter("@whid",s.WareHose_Id),
                                        new SqlParameter("@proid",s.Product_Id),
                                    };
            return helper.ExecNonquery_Proc("AddStock", addstock);
        }
        
        /// <summary>
        /// 库存管理——删除支持多删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DelStock(string id)
        {
            SqlParameter[] delstock ={
                                         new SqlParameter("@id",id)
                                    };
            return helper.ExecNonquery_Proc("DeleteStock", delstock);
        }
        
        /// <summary>
        /// 库存管理——根据编号获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetStockByid(int id)
        {
            SqlParameter[] GetStockByid ={
                                             new SqlParameter("@id",id)
                                        };
            return helper.ExecDataTable_Proc("GetStockById",GetStockByid);
        }
        /// <summary>
        /// 库存管理——修改
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int UpdStockById(Stock s)
        {
            SqlParameter[] updstock ={
                                         new SqlParameter("@id",s.Stock_Id),
                                         new SqlParameter("@num",s.Stock_num),
                                        new SqlParameter("@warm",s.Stock_warn),
                                        new SqlParameter("@whid",s.WareHose_Id),
                                        new SqlParameter("@proid",s.Product_Id),
                                    };
            return helper.ExecNonquery_Proc("UpdStockById", updstock);
        }
        
        /// <summary>
        /// 库存管理——根据商品名称搜索
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public DataTable GetStockByName(string name)
        {
            name = '%' + name + '%';
            SqlParameter[] stockname ={
                                         new SqlParameter("@proname",name),
                                    };
            return helper.ExecDataTable_Proc("GetStockByProname", stockname);
        }
        /// <summary>
        /// 库存管理——显示总条数
        /// </summary>
        /// <returns></returns>
        public int GetStockCount()
        {
            return Convert.ToInt32(helper.ExecScalar_Proc("proc_GetStockNum"));
        }
    }
}
